<?php
class Statistic_Model_Statistic extends Zend_Db_Table{
	protected $_name = 'statistic';
	protected $_primary = 'date';
	
	public  function counthits_day($date)
	{// co dung
		$temp = split('/', $date);
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/statistic/route/counthitsday/ngay/".urlencode($temp[0])."/thang/".urlencode($temp[1])."/nam/".urlencode($temp[2]));
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
		$hits=0;
		if($data!=null)
		{
			foreach ($data as $once)
			{
				$hits+= $once['hits'];
			}
		}
			return  $hits;
			
			
		
	}
	public  function counthits_month($month)
	{// co dung
		
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/Statistic/route/counthitsmonth/monthn/".$month);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
		$hits=0;
		foreach ($data as $once)
			{
				$hits+= $once['hits'];
			}
			return  $hits;
	}
	
	public function addhits($date)
	{	// co dung
		$temp = split('/', $date);
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/statistic/route/addhits/ngay/".urlencode($temp[0])."/thang/".urlencode($temp[1])."/nam/".urlencode($temp[2]));
		//$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
	
	}
	

}